<template>
  <div class="todo-filter">
    <div class="filter-info">
      <span class="task-count">{{ activeCount }} 个待完成</span>
      <button 
        v-if="completedCount > 0" 
        @click="$emit('clear-completed')" 
        class="clear-button"
      >
        清除已完成
      </button>
    </div>
    
    <div class="filter-buttons">
      <button 
        v-for="option in filterOptions" 
        :key="option.value"
        @click="$emit('change-filter', option.value)"
        :class="['filter-button', { active: modelValue === option.value }]"
      >
        {{ option.label }}
      </button>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue';

// 定义props
const props = defineProps({
  activeCount: {
    type: Number,
    required: true
  },
  completedCount: {
    type: Number,
    required: true
  },
  modelValue: {
    type: String,
    default: 'all'
  }
});

// 定义事件
defineEmits(['change-filter', 'clear-completed', 'update:modelValue']);

// 过滤选项
const filterOptions = [
  { label: '全部', value: 'all' },
  { label: '未完成', value: 'active' },
  { label: '已完成', value: 'completed' }
];
</script>

<style scoped>
.todo-filter {
  margin: 20px 0;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.filter-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #7a7a7a;
  font-size: 14px;
}

.task-count {
  font-weight: 500;
}

.clear-button {
  background: none;
  border: none;
  color: #ff6b81;
  cursor: pointer;
  font-size: 14px;
  text-decoration: underline;
  transition: color 0.2s;
}

.clear-button:hover {
  color: #ff4757;
}

.filter-buttons {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.filter-button {
  padding: 6px 12px;
  background-color: #f1f1f1;
  border: none;
  border-radius: 16px;
  color: #666;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 14px;
}

.filter-button:hover {
  background-color: #e0e0e0;
}

.filter-button.active {
  background-color: #41b883;
  color: white;
}
</style> 